#include<bits/stdc++.h>
#define ll long long
using namespace std;
namespace Fastio {
const int L = 1 << 20;
inline char gc() {
    static char buf[L], *l = buf, *r = buf;
    if (l == r)
        r = (l = buf) + fread(buf, 1, L, stdin);
    return (l == r) ? EOF : *l++;
}
char obuf[L], *p = obuf;
inline void pc(char c) {
    if (p == obuf + L)
        fwrite(obuf, 1, L, stdout), p = obuf;
    *p++ = c;
}
inline void flush() { fwrite(obuf, 1, p - obuf, stdout); }
struct Reader {
    template <typename T>
    inline Reader& operator>>(T& x) {
        x = 0;
        short f = 1;
        char c = gc();
        while (!isdigit(c)) {
            if (c == '-')
                f = -1;
            c = gc();
        }
        while (isdigit(c)) x = 10 * x + (c - '0'), c = gc();
        x *= f;
        return *this;
    }
    Reader() {}
} cin;
struct Writer {
    template <typename T>
    inline Writer& operator<<(T x) {
        if (x < 0)
            pc('-'), x = -x;
        static short tp = 0, s[40];
        do
            s[++tp] = x % 10, x /= 10;
        while (x);
        while (tp) pc(s[tp--] + '0');
        return *this;
    }
    inline Writer& operator<<(const char* s) {
        int i = 0;
        while (s[i]) pc(s[i++]);
        return *this;
    }
    inline Writer& operator<<(char c) {
        pc(c);
        return *this;
    }
    Writer() {}
    ~Writer() { flush(); }
} cout;
#define cin Fastio::cin


#define cout Fastio::cout


}
const int N=2e5+5;
int n,Q;
vector<int> son[N],www[N];
int fa[N][22],dep[N],siz[N];
int id[N],cnt,tn,root[N];
ll su[N];
struct sss {
	int ls,rs,val;
} tre[N*22];
inline void push_up(int now) {
	tre[now].val=tre[tre[now].ls].val+tre[tre[now].rs].val;
}
int build(int now,int l,int r) {
	tn=max(now,tn);
	if(l==r) {
		tre[now]={0,0,0};
		return now;
	}
	int mid=(l+r)>>1;
	tre[now].ls=build(now<<1,l,mid);
	tre[now].rs=build(now<<1|1,mid+1,r);
	return now;
}
int update(int now,int l,int r,int t) {
	if(l>t||r<t) return now;
	if(l==r) {
		tre[++tn]=tre[now];
		tre[tn].val++;
		return tn;
	}
	int nw=++tn,mid=(l+r)>>1;
	tre[nw].ls=update(tre[now].ls,l,mid,t);
	tre[nw].rs=update(tre[now].rs,mid+1,r,t);
	push_up(nw);
	return nw;
}
int query(int now,int l,int r,int tl,int tr) {
	if(l>tr||r<tl) return 0;
	if(tl<=l&&r<=tr) return tre[now].val;
	int mid=(l+r)>>1;
	return query(tre[now].ls,l,mid,tl,tr)+query(tre[now].rs,mid+1,r,tl,tr);
}
inline int vis(int L,int R,int l,int r) {
	if(l>r||L>R) return 0;
	return query(root[R],1,n,l,r)-query(root[L-1],1,n,l,r);
}
void dfs1(int now,int fat) {
	fa[now][0]=fat;
	dep[now]=dep[fat]+1;
	id[now]=++cnt;
	root[cnt]=update(root[cnt-1],1,n,now);
	siz[now]=1;
	for(int i=0;i<son[now].size();i++) {
		int to=son[now][i];
		if(to==fat) continue ;
		su[to]=su[now]+www[now][i];
		dfs1(to,now);
		siz[now]+=siz[to];
	}
}
inline int lca(int u,int v) {
	if(u==0) return v;
	if(v==0) return u;
	if(dep[u]<dep[v]) swap(u,v);
	for(int i=20;i>=0;i--) if(dep[fa[u][i]]>=dep[v]) {
		u=fa[u][i];
	}
	if(u==v) {
		return u;
	}
	for(int i=20;i>=0;i--) if(fa[u][i]!=fa[v][i]) {
		u=fa[u][i];
		v=fa[v][i];
	}
	return fa[u][0];
}
struct SGT {
	int tre[N<<2] ;
	void build(int now,int l,int r) {
		if(l==r) {
			tre[now]=l;
			return ;
		}
		int mid=(l+r)>>1;
		build(now<<1,l,mid);
		build(now<<1|1,mid+1,r);
		tre[now]=lca(tre[now<<1],tre[now<<1|1]);
	}
	int query(int now,int l,int r,int tl,int tr) {
		if(l>tr||r<tl) return 0;
		if(tl<=l&&r<=tr) return tre[now];
		int mid=(l+r)>>1;
		return lca(query(now<<1,l,mid,tl,tr),query(now<<1|1,mid+1,r,tl,tr));
	}
} T;
signed main() {
	freopen("memory.in","r",stdin);
	freopen("memory.out","w",stdout);
	ios::sync_with_stdio(0);
	cin>>n>>Q;
	int u,v,w;
	for(int i=1;i<n;i++) {
		cin>>u>>v>>w;
		son[u].push_back(v);
		www[u].push_back(w);
		son[v].push_back(u);
		www[v].push_back(w);
	}
	root[0]=build(1,1,n);
	dfs1(1,0);
	for(int j=1;j<=20;j++) {
		for(int i=1;i<=n;i++)
			fa[i][j]=fa[fa[i][j-1]][j-1];
	}
	T.build(1,1,n);
	ll p,l,r,last=0;
	while(Q--) {
		cin>>p>>l>>r;
		p^=last,l^=last,r^=last;
		int L=id[p],R=id[p]+siz[p]-1;
		ll ans=0;
		int k=siz[p]-vis(L,R,1,l-1)-vis(L,R,r+1,n);
		if(k==r-l+1) {
			int o=T.query(1,1,n,l,r);
			ans=su[o]-su[p]; 
//			cout<<"F1 "<<l<<" "<<r<<" "<<o<<"\n";
		} else {
			if(k>0) {
				ans=0;
//				cout<<"F2\n";
			} else {
				int pp=p;
				for(int i=20;i>=0;i--) {
					if(fa[p][i]==0) continue ;
					L=id[fa[p][i]],R=id[fa[p][i]]+siz[fa[p][i]]-1;
					if(vis(L,R,1,l-1)+vis(L,R,r+1,n)==siz[fa[p][i]]) {
						p=fa[p][i];
					}
				}
				p=fa[p][0];
				ans=su[pp]-su[p];
				int o=T.query(1,1,n,l,r);
				if(id[p]<=id[o]&&id[o]<id[p]+siz[p]) {
					ans+=su[o]-su[p];
				}
//				cout<<"F3\n";
			}
		}
		cout<<ans<<"\n";
		last=ans;
	}
	return 0;
}

